import { Injectable } from '@angular/core';
import { BaseService } from './base.service';
import { OrganizationInfo } from '../models';

@Injectable({
  providedIn: 'root'
})
export class OrganizationService extends BaseService {
  saveOrgCodeRules(datas) {
    const url = `api/orgCodeRule`;
    return this.post(url, datas);
  }

  async getOrgCodeSetting(orgId) {
    const url = `api/organization/${orgId}/orgCodeRule`;
    return this.get(url);
  }

  getNewOrgCode(orgCodeRuleName: string) {
    let url = `api/orgCodeRule/gcode?orgCodeRuleName=${orgCodeRuleName}`;
    return this.get(url);
  }

  saveOrgCode(seedId: string) {
    let orgId = localStorage.getItem('orgid');
    let url = `api/organization/${orgId}/orgCodeSeed/${seedId}`;
    return this.put(url);
  }

  //上传图片前缀域名
  geturlAddress() {
    return this.uploadUrl;
  }
  //添加组织
  createOrganization(params: OrganizationInfo) {
    const url = 'api/organization';
    return this.post(url, params);
  }
  //编辑组织
  updateOrganization(OrganizationInfo) {
    const url = 'api/organization';
    return this.put(url, OrganizationInfo);
  }
  //查看详情组织
  getOrganizationInfoById(id) {
    const url = 'api/organization';
    return this.get(`${url}/${id}`);
  }
  //组织列表
  organizationList(params: { name: string; status: string; pageIndex: number; countOfPage: number; }) {
    const url = 'api/organization';
    return this.get(url, { params });
  }
  //删除组织
  deleteOrganization(id) {
    const url = 'api/organization';
    return this.delete(`${url}/${id}`);
  }
  //组织机构树列表 objectName=Department
  getOrganizationTrees(params: {
    organizationId?: string;
    objectName?: string | string[];
    [key: string]: any
  }) {
    const url = 'api/organizationTree';
    return this.get(url, { params });
  }
  //组织详情
  getOrganizationTreeInfoById(id: string) {
    const url = 'api/organizationTree';
    return this.get(`${url}/${id}`);
  }

  //编辑树形节点
  updateorganizationTree(list) {
    const url = 'api/organizationTree';
    return this.put(url, list);
  }
}
